# !/usr/bin/python3
# -*- coding: utf-8 -*-
# @Time    : 2021/9/30 13:34
# @Author  : zuodengbo
# @Email   : zuodb@amoydx.com
# @File    : schemas
# @Software: PyCharm

REGISTER_SCHEMA = {
    "username": {
        "type": "string",
        "minlength": 3,
        "maxlength": 20,
        "regex": r"^[0-9a-zA-Z_]{3,20}",
        "required": True,
    },
    "name": {
        "type": "string",
        "minlength": 3,
        "maxlength": 32,
        "required": True,
    },
    "password": {
        "type": "string",
        "minlength": 8,
        "maxlength": 64,
        "required": True
    },
    "verify_code": {
        "type": "string",
        "minlength": 6,
        "maxlength": 6,
        "required": True
    },
    "email": {
        "type": "string",
        "minlength": 10,
        "maxlength": 32,
        "regex": r"^[0-9a-zA-Z_]{0,19}@[0-9a-zA-Z]{1,13}\.[com,cn,net,gov]{1,3}$",
        "required": True
    },
    "phone": {
        "type": "string",
        "minlength": 11,
        "maxlength": 11,
        "regex": r"[1][3456789]\d{9}",
        "required": True
    },
}

LOGIN_SCHEMA = {
    "username": {
        "type": "string",
        "minlength": 3,
        "maxlength": 20,
        "regex": r"^[0-9a-zA-Z_]{3,20}",
        "required": True,
    },
    "password": {
        "type": "string",
        "minlength": 8,
        "maxlength": 64,
        "required": True
    },
    "verify_code": {
        "type": "string",
        "minlength": 6,
        "maxlength": 6,
        "required": True
    },
}

PHONE_LOGIN_SCHEMA = {
    "phone": {
        "type": "string",
        "minlength": 11,
        "maxlength": 11,
        "regex": r"^^1(3[0-9]|4[5,7]|5[0,1,2,3,5,6,7,8,9]|6[2,5,6,7]|7[0,1,7,8]|8[0-9]|9[1,8,9])\d{8}$",
        "required": True,
    },
    "sms_code": {
        "type": "string",
        "minlength": 6,
        "maxlength": 6,
        "required": True
    },
}

ADD_USER_SCHEMA = {
    "username": {
        "type": "string",
        "minlength": 3,
        "maxlength": 20,
        "regex": r"^[0-9a-zA-Z_]{3,20}",
        "required": True,
    },
    "name": {
        "type": "string",
        "minlength": 3,
        "maxlength": 32,
        "required": True,
    },
    "password": {
        "type": "string",
        "minlength": 8,
        "maxlength": 64,
        "required": True
    },
    "email": {
        "type": "string",
        "minlength": 10,
        "maxlength": 32,
        "regex": r"^[0-9a-zA-Z_]{0,19}@[0-9a-zA-Z]{1,13}\.[com,cn,net]{1,3}$",
        "required": True
    },
    "phone": {
        "type": "string",
        "minlength": 11,
        "maxlength": 11,
        "regex": r"[1][345789]\d{9}",
        "required": True
    },
}

COMMON_SCHEMA = {
    "keyword": {
        "type": "string",
        "required": False,
    },
    "page_num": {
        "type": "string",
        "minlength": 1,
        "maxlength": 3,
        "required": False,
    },
    "page_size": {
        "type": "string",
        "minlength": 1,
        "maxlength": 4,
        "required": False
    },
}

COMMON_ID_SCHEMA = {
    "id": {
        "oneof": [
            {"type": "string"},
            {"type": "integer"}
        ],
        "required": True,
    },
}

ROLE_SCHEMA = {
    "code": {
        "type": "string",
        "minlength": 4,
        "maxlength": 32,
        "regex": r"^[0-9a-zA-Z_]{3,32}",
        "required": True,
    },
    "role_name": {
        "type": "string",
        "minlength": 3,
        "maxlength": 32,
        "required": True
    },
    "status": {
        "type": "integer",
        "minlength": 1,
        "maxlength": 1,
        "required": False
    },
}

ROLE_INFO_SCHEMA = {
    "id": {
        "oneof": [
            {"type": "string"},
            {"type": "integer"}
        ],
        "minlength": 1,
        "maxlength": 32,
        "required": True
    },
    "code": {
        "type": "string",
        "minlength": 4,
        "maxlength": 32,
        "regex": r"^[0-9a-zA-Z_]{3,32}",
        "required": True,
    },
    "name": {
        "type": "string",
        "minlength": 3,
        "maxlength": 32,
        "required": True
    },
    "status": {
        "oneof": [
            {"type": "string"},
            {"type": "integer"}
        ],
        "minlength": 1,
        "maxlength": 1,
        "required": True
    },
    "creator": {
        "oneof": [
            {"type": "string"},
            {"type": "integer"}
        ],
        "minlength": 1,
        "maxlength": 32,
        "required": True
    },
    "create_time": {
        "type": "string",
        "required": False
    },
    "update_time": {
        "type": "string",
        "required": False
    },
}

AUTHORITY_SCHEMA = {
    "code": {
        "type": "string",
        "minlength": 4,
        "maxlength": 32,
        "regex": r"^[0-9a-zA-Z_]{3,32}",
        "required": True,
    },
    "name": {
        "type": "string",
        "minlength": 4,
        "maxlength": 32,
        "required": True
    },
    "type": {
        "oneof": [
            {"type": "string"},
            {"type": "integer"}
        ],
        "minlength": 1,
        "maxlength": 1,
        "required": True
    },
    "uri": {
        "type": "string",
        "maxlength": 128,
        "required": False
    },
    "path": {
        "type": "string",
        "maxlength": 128,
        "required": False
    },
    "icon": {
        "type": "string",
        "maxlength": 128,
        "required": False
    },
    "status": {
        "oneof": [
            {"type": "string"},
            {"type": "integer"}
        ],
        "required": False
    },
    "parent_id": {
        "oneof": [
            {"type": "string"},
            {"type": "integer"}
        ],
        "required": False
    },
}

AUTHORITY_INFO_SCHEMA = {
    "id": {
        "oneof": [
            {"type": "string"},
            {"type": "integer"}
        ],
        "minlength": 1,
        "maxlength": 32,
        "required": True
    },
    "code": {
        "type": "string",
        "minlength": 4,
        "maxlength": 32,
        "regex": r"^[0-9a-zA-Z_]{3,32}",
        "required": True,
    },
    "name": {
        "type": "string",
        "minlength": 3,
        "maxlength": 32,
        "required": True
    },
    "uri": {
        "type": "string",
        "required": False
    },
    "type": {
        "oneof": [
            {"type": "string"},
            {"type": "integer"}
        ],
        "minlength": 1,
        "maxlength": 1,
        "required": True
    },
    "status": {
        "oneof": [
            {"type": "string"},
            {"type": "integer"}
        ],
        "minlength": 1,
        "maxlength": 1,
        "required": True
    },
    "parent_id": {
        "oneof": [
            {"type": "string"},
            {"type": "integer"}
        ],
        "required": False
    },
    "icon": {
        "type": "string",
        "required": False
    },
    "path": {
        "type": "string",
        "required": False
    },
    "create_time": {
        "type": "string",
        "required": False
    },
    "update_time": {
        "type": "string",
        "required": False
    },
}

USER_ROLE_SCHEMA = {
    "username": {
        "type": "string",
        "minlength": 1,
        "maxlength": 20,
        "required": True,
    },
    "role_name": {
        "type": "string",
        "maxlength": 32,
        "required": True
    },
}

ROLE_OR_AUTHORITY_SCHEMA = {
    "model": {
        "type": "string",
        "minlength": 1,
        "maxlength": 32,
        "required": True
    },
    "id": {
        "type": "string",
        "required": False
    },
}

ROLE_AUTHORITY_SCHEMA = {
    "perm_ids": {
        "type": "list",
        "maxlength": 256,
        "required": True,
    },
    "role_id": {
        "type": "integer",
        "maxlength": 32,
        "required": True
    },
}

USER_INFO_SCHEMA = {
    "user_info": {
        "type": "dict",
        "required": True
    },
    "role_info": {
        "type": "dict",
        "required": True
    },
    "job_info": {
        "type": "dict",
        "required": True
    },
}

CHANGE_PWD_SCHEMA = {
    "old_pwd": {
        "type": "string",
        "minlength": 8,
        "maxlength": 64,
        "required": True
    },
    "new_pwd": {
        "type": "string",
        "minlength": 8,
        "maxlength": 64,
        "required": True
    },
}

USER_SCHEMA = {
    "email": {
        "type": "string",
        "minlength": 10,
        "maxlength": 32,
        "regex": r"^[0-9a-zA-Z_]{3,19}@[0-9a-zA-Z]{2,13}\.[com,cn,net]{1,3}$",
        "required": True
    },
    "phone": {
        "type": "string",
        "minlength": 11,
        "maxlength": 11,
        "regex": r"[1][345789]\d{9}",
        "required": True
    },
    "age": {
        "type": "integer",
        "maxlength": 3,
        "required": False
    },
    "gender": {
        "type": "string",
        "maxlength": 10,
        "required": False
    },
    "birthday": {
        "type": "string",
        "required": False
    },
    "address": {
        "type": "string",
        "maxlength": 100,
        "required": False
    },
    "remark": {
        "type": "string",
        "required": False
    },
}

PHONE_EMAIL_SCHEMA = {
    "phone": {
        "type": "string",
        "minlength": 11,
        "maxlength": 11,
        "required": False
    },
    "email": {
        "type": "string",
        "minlength": 8,
        "maxlength": 32,
        "required": False
    },
}

RESET_PWD_SCHEMA = {
    "phone_or_email": {
        "type": "string",
        "minlength": 8,
        "maxlength": 32,
        "required": True
    },
    "verify_code": {
        "type": "string",
        "minlength": 6,
        "maxlength": 6,
        "required": True
    },
    "new_pwd": {
        "type": "string",
        "minlength": 8,
        "maxlength": 64,
        "required": True
    },
}
